
#include <stdio.h>
#include "sample.h"


Parseur::Parseur(){
}

Parseur::~Parseur(){
}

// Fonction qui renvoie le Vecteur des machines de la grappe d'état 



// Fonction qui renvoie la valeur de la balise 

xmlChar* Parseur::parseStory (xmlDocPtr doc, xmlNodePtr cur,char *keyword) {
         xmlChar *key;
          cur = cur->xmlChildrenNode;
          while (cur != NULL) {
             if ((!xmlStrcmp(cur->name, (const xmlChar *)keyword))) {
               key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
                  
              }
         cur = cur->next;
         }
     return key;
}

// fonction qui parse le fichier XML 

xmlDocPtr Parseur::parseDoc(char *docname, char *keyword) {
        xmlDocPtr doc;
        xmlNodePtr cur,cur1;
        doc = xmlParseFile(docname);
        if (doc == NULL ) {
                fprintf(stderr,"Document not parsed successfully. \n");
                return (NULL);
        }
        cur = xmlDocGetRootElement(doc);
        if (cur == NULL) {
                fprintf(stderr,"empty document\n");
                xmlFreeDoc(doc);
                return (NULL);
        }
        if (xmlStrcmp(cur->name, (const xmlChar *) "GRAPPE")) {
                fprintf(stderr,"document of the wrong type, root node != story");
                xmlFreeDoc(doc);
                return (NULL);
        }
	//Grappe *grappe=NULL;
        cur1 = cur->xmlChildrenNode;
        while (cur1 != NULL) {
                if ((!xmlStrcmp(cur1->name, (const xmlChar *)"machine"))){
                         char* ipadresse=(char*)parseStory (doc, cur1,"IPADRESSE");
			 char* cpu_mhz=(char*)parseStory (doc, cur1,"CPU_MHz");
			 char* model_name=(char*)parseStory (doc, cur1,"MODEL_NAME");
			 char* cpu_family=(char*)parseStory (doc, cur1,"CPU_FAMILY");
			 char* cache_size=(char*)parseStory (doc, cur1,"CACHE_SIZE");
			 char* bogomips=(char*)parseStory (doc, cur1,"BOGOMIPS");
			 char* cpuid_level=(char*)parseStory (doc, cur1,"CPUID_LEVEL");
			 char* rtt=(char*)parseStory (doc, cur1,"RTT");
			 char* debit=(char*)parseStory (doc, cur1,"Debit");
			 char* latence=(char*)parseStory (doc, cur1,"Latence");
			 
                }
       		 cur1 = cur1->next;
        }
        return(doc);
}



